package com.stablesoft.gamestat.data.wot;

import android.content.Context;
import android.os.AsyncTask;
import android.text.format.Time;

public class LoadDataTask extends AsyncTask<Void, Void, Dataset> {
	Context mContext;

	public LoadDataTask(Context context) {
		mContext = context;
	}

	@Override
	protected Dataset doInBackground(Void... params) {
		
		Time yesterdayTime = new Time();
		yesterdayTime.setToNow();
		yesterdayTime.set(yesterdayTime.toMillis(true) - 24*60*60*1000);
			
		DBHandler db = new DBHandler(mContext);
		Time lastUpdate = db.getLastUpdate();
		
		Dataset ds;

		if(lastUpdate == null || lastUpdate.before(yesterdayTime)) {
			ds = downloadStatistic();
			if (ds != null)
				ds.saveSnapshot(db);
		} 
		else {
			ds = new Dataset();
			ds.loadFromDB(db);
		}
		return ds;
	}

	private Dataset downloadStatistic() {
		// TODO Auto-generated method stub
		return null;
	}

}
